//CORNUGON TELEPORT WITHOUT ERROR SCRIPT SIMULATION
//BY MAGMA - 8 JUNE 2003
//GETS THE HOSTILE PC WITH THE GREATEST MAX HIT POINTS AND TELEPORTS TO IT

void main()
{
   int nth=0;
   object opc;  // Current PC
   object opowerful; // The most powerful PC
   location lpowerful; // The place it is at
   location lcreature; // The place the teleporting creature is
   int maxhealth; // The most health found so far
   do
      { // FINDS THE PC IT IS HOSTILE TO WITH THE MOST MAX HEALTH
         nth++;
         opc = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, nth);
         if (GetReputation(opc, OBJECT_SELF)<11) // If creature hates the PC
            {
               if (GetMaxHitPoints(opc)>maxhealth) // And if maximum health is a record
                  {
                     maxhealth=GetMaxHitPoints(opc); // Update the maximum health record
                     opowerful=opc; // And set the most powerful PC as the one just found
                  }
            }
      }
   while (GetIsObjectValid(opc)); // Loop until no valid PCs remain
   lpowerful=GetLocation(opowerful);
   lcreature=GetLocation(OBJECT_SELF);
   ApplyEffectAtLocation(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_IMP_UNSUMMON,FALSE),lcreature);
   JumpToLocation(lpowerful);
   ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_IMP_UNSUMMON,FALSE),OBJECT_SELF);
}
